﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Transactions;

public partial class WebForm_LeaveData_Apply : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Form1.LoadData(FormViewMode.Insert, null);
            gv.DataBind();
        }
    }

    protected void btnBack_Click(object sender, EventArgs e)
    {
        gv.DataBind();
    }

    protected void gv_ItemCommand(object sender, GridViewCommandEventArgs e)
    {
        switch (e.CommandName)
        {
            case "MyDelete":
                var row = (e.CommandSource as Control).NamingContainer as GridViewRow;
                var db = new DB("Attendance");

                using (TransactionScope scope = new TransactionScope())
                {
                    db.ExecuteNonQuery("UPDATE LeaveData SET Status='D' WHERE LeaveID=@LeaveID"
                        , new DBParameter("LeaveID", gv.DataKeys[row.RowIndex]["LeaveID"]));

                    scope.Complete();
                }

                gv.DataBind();

                break;

            default:
                break;
        }
    }

    protected void Form1_Saved(object sender, EventArgs e)
    {
        gv.DataBind();
    }
}